home *** CD-ROM | disk | FTP | other *** search
/ Painter Bear's Language Bridge — Italian / Bridge_ponte_itialian.iso / pc / helpers / open.dxr / 00014_text layouts.ls < prev    next >
Encoding:
Text File  |  2001-02-22  |  6.2 KB  |  183 lines

  1. on setboxSize whichBox
  2.   global gStageAcross, gStageUpDown, gBoxLeft, gBoxTop
  3.   case whichBox of
  4.     "questBox":
  5.       set gBoxLeft to 304
  6.       set right to 615
  7.       set gBoxTop to 55
  8.       set bottom to 315
  9.     "ans1":
  10.       set gBoxLeft to 85
  11.       set right to 586
  12.       set gBoxTop to 346
  13.       set bottom to 373
  14.     "ans2":
  15.       set gBoxLeft to 85
  16.       set right to 586
  17.       set gBoxTop to 379
  18.       set bottom to 406
  19.     "ans3":
  20.       set gBoxLeft to 85
  21.       set right to 586
  22.       set gBoxTop to 415
  23.       set bottom to 442
  24.     "ans4":
  25.       set gBoxLeft to 85
  26.       set right to 586
  27.       set gBoxTop to 450
  28.       set bottom to 477
  29.   end case
  30.   set gStageAcross to abs(right - gBoxLeft)
  31.   set gStageUpDown to abs(gBoxTop - bottom)
  32. end
  33.  
  34. on countAndCenterText centerWhat, whatColor, howSo
  35.   global gStageAcross, gStageUpDown, gBoxLeft, gSpaceWidth, gBoxTop, gDontCenter
  36.   set gSpaceWidth to 10
  37.   set letterLst to []
  38.   set lineLst to []
  39.   set txtWdthLst to []
  40.   set textWidth to 0
  41.   set numOfLines to 1
  42.   set xtraHeight to 3
  43.   set wordLnLst to []
  44.   repeat with c = 1 to the number of words in centerWhat
  45.     set thisWord to word c of centerWhat
  46.     if c = 1 then
  47.       set wordWidth to 0
  48.       set wordLst to []
  49.     else
  50.       set wordWidth to gSpaceWidth
  51.       set wordLst to [SPACE]
  52.     end if
  53.     if whatColor = "ran" then
  54.       case random(4) of
  55.         "1":
  56.           set whichColor to "red"
  57.         "2":
  58.           set whichColor to "yel"
  59.         "3":
  60.           set whichColor to "grn"
  61.         "4":
  62.           set whichColor to "pur"
  63.       end case
  64.     else
  65.       set whichColor to whatColor
  66.     end if
  67.     repeat with w = 1 to the number of chars in thisWord
  68.       set thisChar to char w of thisWord
  69.       set thisChar to getCharCode(thisChar)
  70.       set charWidth to the width of member (thisChar & SPACE & whichColor)
  71.       set wordWidth to wordWidth + charWidth
  72.       set indLettLst to [thisChar & SPACE & whichColor]
  73.       add(wordLst, indLettLst)
  74.     end repeat
  75.     if (textWidth + wordWidth) <= gStageAcross then
  76.       set textWidth to textWidth + wordWidth
  77.       add(lineLst, wordLst)
  78.       add(wordLnLst, thisWord)
  79.       next repeat
  80.     end if
  81.     add(letterLst, lineLst)
  82.     add(txtWdthLst, textWidth)
  83.     set textWidth to wordWidth
  84.     set lineLst to [wordLst]
  85.     set wordLnLst to [thisWord]
  86.   end repeat
  87.   add(letterLst, lineLst)
  88.   add(txtWdthLst, textWidth)
  89.   set tempLst to []
  90.   set numLines to count(letterLst)
  91.   set letterHeight to the height of member ("48 " & whichColor)
  92.   if gStageUpDown > integer(numLines * letterHeight) then
  93.     set diff to integer((gStageUpDown - (numLines * letterHeight)) / 2)
  94.     set startV to gBoxTop + diff + integer(letterHeight / 2)
  95.     repeat with Y = 1 to count(letterLst)
  96.       set thisLine to getAt(letterLst, Y)
  97.       set textWidth to value(getAt(txtWdthLst, Y))
  98.       set otherDiff to integer((gStageAcross - textWidth) / 2)
  99.       if howSo = "center" then
  100.         set startH to gBoxLeft + otherDiff
  101.       else
  102.         if howSo = "left" then
  103.           set startH to gBoxLeft + gSpaceWidth
  104.         end if
  105.       end if
  106.       repeat with w = 1 to count(thisLine)
  107.         set thisWord to getAt(thisLine, w)
  108.         repeat with m = 1 to count(thisWord)
  109.           set thisLetter to getAt(thisWord, m)
  110.           if thisLetter <> SPACE then
  111.             set thisChar to getAt(thisLetter, 1)
  112.             set startH to integer(startH + (the width of member thisChar / 2))
  113.             set nextH to integer(the width of member thisChar / 2)
  114.             add(thisLetter, startH)
  115.             add(thisLetter, startV)
  116.             set startH to startH + nextH
  117.             next repeat
  118.           end if
  119.           set startH to startH + gSpaceWidth
  120.         end repeat
  121.       end repeat
  122.       set startV to startV + letterHeight + xtraHeight
  123.     end repeat
  124.   else
  125.     alert("too many lines! " & centerWhat)
  126.     set gDontCenter to 1
  127.   end if
  128.   return letterLst
  129. end
  130.  
  131. on stampOutTxt whichTxt, whichSprite, trails
  132.   global gNoTrailSprite, gLastNoTrailsSprt, gDontCenter
  133.   if gDontCenter = 1 then
  134.     set gDontCenter to 0
  135.   else
  136.     repeat with Y = 1 to count(whichTxt)
  137.       set thisLine to getAt(whichTxt, Y)
  138.       repeat with w = 1 to count(thisLine)
  139.         set thisWord to getAt(thisLine, w)
  140.         repeat with m = 1 to count(thisWord)
  141.           if trails = 0 then
  142.             set whichSprite to gNoTrailSprite
  143.           end if
  144.           set thisLetter to getAt(thisWord, m)
  145.           if thisLetter <> SPACE then
  146.             set thisChar to getAt(thisLetter, 1)
  147.             set thisH to value(getAt(thisLetter, 2))
  148.             set thisV to value(getAt(thisLetter, 3))
  149.             set the memberNum of sprite whichSprite to the number of member thisChar
  150.             set the width of sprite whichSprite to the width of member thisChar
  151.             set the height of sprite whichSprite to the height of member thisChar
  152.             set the loc of sprite whichSprite to point(thisH, thisV)
  153.             if not soundBusy(2) then
  154.             end if
  155.             updateStage()
  156.             if trails = 1 then
  157.               updateStage()
  158.               set the loc of sprite whichSprite to point(-100, -100)
  159.               next repeat
  160.             end if
  161.             set gNoTrailSprite to gNoTrailSprite + 1
  162.             if gNoTrailSprite = gLastNoTrailsSprt then
  163.               alert(string(the myAnswerLst of getAt(gProbLst, 1)))
  164.               exit repeat
  165.             end if
  166.           end if
  167.         end repeat
  168.       end repeat
  169.     end repeat
  170.   end if
  171. end
  172.  
  173. on getCharCode thisChar
  174.   set asciiLst to ["√Ñ", "142", "√ñ", "153", "√ú", "154", "√ü", "225", "√§", "132", "√∂", "148", "√º", "129", "√°", "160", "√©", "130", "√≠", "161", "√±", "164", "√≥", "162", "√∫", "163", "√Å", "253", "√â", "144", "√ç", "252", "√ë", "165", "√ì", "251", "√ö", "250", "√†", "133", "√¢", "131", "√ß", "135", "√™", "136", "√´", "137", "√Ø", "139", "√Æ", "140", "√¥", "147", "≈ì", "249", "√π", "151", "√ª", "150", "√Ä", "248", "√Ç", "247", "√á", "128", "√ä", "246", "√ã", "245", "√à", "244", "√è", "243", "√é", "242", "√î", "241", "≈í", "240", "√ô", "239", "√õ", "238", "√®", "138", "√¨", "141", "√≤", "149", "√å", "237", "√í", "236", "¬ø", "168", "¬°", "255"]
  175.   set aPos to getPos(asciiLst, thisChar)
  176.   if aPos <> 0 then
  177.     set aNum to value(getAt(asciiLst, aPos + 1))
  178.   else
  179.     set aNum to charToNum(thisChar)
  180.   end if
  181.   return aNum
  182. end
  183.